/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroProduto.java
 *
 * Created on 16/08/2010, 09:34:27
 */
package view;

import DAO.EstoqueDAO;
import DAO.FornecedorDAO;
import DAO.ProdutoDAO;
import controller.Fornecedor;
import controller.Produto;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Alcivando
 */
public class CadastroProduto extends javax.swing.JInternalFrame {

    ProdutoDAO dao;
    Produto produto;
    DefaultTableModel modeloP;
    DefaultTableModel modeloF;
    FornecedorDAO fdao;
    private static final CadastroProduto cadProduto;

    static {
        cadProduto = new CadastroProduto();
    }

    public static CadastroProduto getInstancia() {
        return cadProduto;
    }

    public CadastroProduto() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        txtNomeF = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtCodigoF = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtRepresentante = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabFornecedor = new javax.swing.JTable();
        txtPesquisaF = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        filtro2 = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        btnNovoCliente = new javax.swing.JButton();
        btnSalvarCliente = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtNomeP = new javax.swing.JTextField();
        txtPreco = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtTamanho = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtEstoqueMin = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtMarca = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("Cadastro de Produtos");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados do Fornecedor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        txtNomeF.setEnabled(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Empresa Fantasia");

        txtCodigoF.setEditable(false);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setText("Código");

        txtRepresentante.setEnabled(false);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Nome Representante");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(txtCodigoF, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtRepresentante, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNomeF, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addContainerGap(125, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtNomeF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(24, 24, 24))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(24, 24, 24))
                            .addComponent(txtRepresentante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addGap(4, 4, 4)
                            .addComponent(txtCodigoF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        tabFornecedor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabFornecedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabFornecedorMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tabFornecedor);

        txtPesquisaF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesquisaFActionPerformed(evt);
            }
        });
        txtPesquisaF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisaFKeyReleased(evt);
            }
        });

        jLabel4.setText("Pesquisar pelo");

        filtro2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Representante", "Código", "Nome Fantasia" }));
        filtro2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filtro2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filtro2, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(txtPesquisaF, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addGap(123, 123, 123))
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtPesquisaF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filtro2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Pesquisar Fornecedor", jPanel8);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder()));

        btnNovoCliente.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btnNovoCliente.setText("Novo ");
        btnNovoCliente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovoCliente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoClienteActionPerformed(evt);
            }
        });

        btnSalvarCliente.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnSalvarCliente.setText("Salvar");
        btnSalvarCliente.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSalvarCliente.setMaximumSize(new java.awt.Dimension(83, 83));
        btnSalvarCliente.setMinimumSize(new java.awt.Dimension(83, 83));
        btnSalvarCliente.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSalvarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarClienteActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnCancelar.setText("Cancelar");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSalvarCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .addComponent(btnNovoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancelar, btnNovoCliente, btnSalvarCliente});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(btnNovoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSalvarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnCancelar, btnSalvarCliente});

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Preço");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Nome");

        txtCodigo.setEditable(false);
        txtCodigo.setEnabled(false);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setText("Código");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel8.setText("Tamanho");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel10.setText("Qtd Min.");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel12.setText("Marca");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(txtNomeP, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtPreco, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(txtTamanho, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(txtEstoqueMin, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(txtMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTamanho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPreco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtNomeP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel9)
                            .addGap(4, 4, 4)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEstoqueMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, 0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNovoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoClienteActionPerformed

        txtNomeP.setText("");
        txtCodigo.setText("");
        txtPreco.setText("");
        txtNomeF.setText("");
        txtCodigoF.setText("");
        txtRepresentante.setText("");
        txtEstoqueMin.setText("");
        txtTamanho.setText("");
        txtMarca.setText("");


        txtPesquisaF.setEnabled(true);
        filtro2.setEnabled(true);

        txtNomeP.setEnabled(true);
        txtPreco.setEnabled(true);
        txtEstoqueMin.setEnabled(true);
        txtMarca.setEnabled(true);
        txtTamanho.setEnabled(true);

        try {
            dao = new ProdutoDAO();
            txtCodigo.setText(Integer.toString(dao.retornaProximoID()));
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
        btnSalvarCliente.setEnabled(true);
//        btnExluirCliente.setEnabled(false);
//        btnAlterar.setEnabled(false);
        btnNovoCliente.setEnabled(false);
        btnCancelar.setEnabled(true);

}//GEN-LAST:event_btnNovoClienteActionPerformed

    private void btnSalvarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarClienteActionPerformed

        try {
            if (txtNomeP.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Erro: Você não preencheu corretamente algum dos campos.", "Erro", 0);

            } else {
                produto = new Produto();
                produto.setCodProduto(Integer.parseInt(txtCodigo.getText().toUpperCase()));
                produto.setNome(txtNomeP.getText().toUpperCase());
                produto.setPreco(Double.parseDouble(txtPreco.getText()));
                produto.setCodFornecedor(Integer.parseInt(txtCodigoF.getText()));
                produto.setTamanho(txtTamanho.getText().toUpperCase());
                produto.setEstoqueMin(Integer.parseInt(txtEstoqueMin.getText().toUpperCase()));
                produto.setMarca(txtMarca.getText().toUpperCase());

                txtNomeP.setText("");
                txtCodigo.setText("");
                txtPreco.setText("");
                txtNomeF.setText("");
                txtCodigoF.setText("");
                txtRepresentante.setText("");
                txtMarca.setText("");
                txtEstoqueMin.setText("");
                txtTamanho.setText("");
                txtPesquisaF.setText("");

                txtPesquisaFKeyReleased(null);

                dao = new ProdutoDAO();
                dao.adiciona(produto);
                EstoqueDAO edao = new EstoqueDAO();

                edao.adicionaProdutoEmEstoque(produto);

//                JOptionPane.showMessageDialog(null, "Cadastro Concluído!", "Concluído", 1);

//                btnExluirCliente.setEnabled(false);
//                btnAlterar.setEnabled(false);
                btnNovoCliente.setEnabled(true);
                btnSalvarCliente.setEnabled(false);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);


        }
}//GEN-LAST:event_btnSalvarClienteActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        txtNomeP.setText("");
        txtCodigo.setText("");
        txtPreco.setText("");
        txtNomeF.setText("");
        txtCodigoF.setText("");
        txtRepresentante.setText("");
        txtPesquisaF.setText("");


//        btnExluirCliente.setEnabled(false);
//        btnAlterar.setEnabled(false);
        btnNovoCliente.setEnabled(true);
        btnSalvarCliente.setEnabled(false);
        btnCancelar.setEnabled(true);

        txtPesquisaF.setEnabled(false);
        filtro2.setEnabled(false);
        
        txtNomeP.setEnabled(false);
        txtCodigo.setEnabled(false);
        txtPreco.setEnabled(false);
        txtPesquisaFKeyReleased(
                null);

    }//GEN-LAST:event_btnCancelarActionPerformed

    private void filtro2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filtro2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_filtro2ActionPerformed

    private void txtPesquisaFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaFKeyReleased
        txtPreco.setEnabled(false);
        txtNomeP.setEnabled(false);
        txtEstoqueMin.setEnabled(false);
        txtMarca.setEnabled(false);
        txtPreco.setEnabled(false);
        txtTamanho.setEnabled(false);

        modeloF.setNumRows(0);

        ArrayList<Fornecedor> listaFornecedor;




        try {

            fdao = new FornecedorDAO();



            if (!txtPesquisaF.getText().isEmpty()) {
                if (filtro2.getSelectedItem().toString().equals("Representante")) {
                    listaFornecedor = fdao.retornaFornecedorPorNome(txtPesquisaF.getText().toUpperCase());


                } else if (filtro2.getSelectedItem().toString().equals("Código")) {
                    listaFornecedor = fdao.retornaFornecedorPorCod(Integer.parseInt(txtPesquisaF.getText().toUpperCase()));


                } else {
                    listaFornecedor = fdao.retornaFornecedorPorNomeEmpresa(txtPesquisaF.getText().toUpperCase());


                }
                for (Fornecedor f : listaFornecedor) {
                    modeloF.addRow(new String[]{Integer.toString(f.getCodFornecedor()), f.getRepresentante(), f.getNomeEmpresa()});


                }
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);



        }
    }//GEN-LAST:event_txtPesquisaFKeyReleased

    private void txtPesquisaFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesquisaFActionPerformed
}//GEN-LAST:event_txtPesquisaFActionPerformed

    private void tabFornecedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabFornecedorMouseClicked

        int linha = tabFornecedor.getSelectedRow();


        try {

            Fornecedor f = new Fornecedor();
            fdao = new FornecedorDAO();
            f = fdao.retornaFornecedorPorCodigo(Integer.parseInt(tabFornecedor.getValueAt(linha, 0).toString()));

            txtCodigoF.setText(Integer.toString(f.getCodFornecedor()));
            txtNomeF.setText(f.getNomeEmpresa());
            txtRepresentante.setText(f.getRepresentante());


            btnSalvarCliente.setEnabled(true);
            btnNovoCliente.setEnabled(false);
//            btnAlterar.setEnabled(false);
//            btnExluirCliente.setEnabled(false);

            txtPreco.setEnabled(true);
            txtNomeP.setEnabled(true);
            txtEstoqueMin.setEnabled(true);
            txtMarca.setEnabled(true);
            txtTamanho.setEnabled(true);



        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);


        }
}//GEN-LAST:event_tabFornecedorMouseClicked

    private void formWindowOpenedF(java.awt.event.WindowEvent evt) {

        //TABELA
        String[] colunasF = new String[]{"", "", ""};
        String[][] dadosF = new String[][]{};

        modeloF = new DefaultTableModel(dadosF, colunasF);

        tabFornecedor.setModel(modeloF);
        tabFornecedor.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Código");
        tabFornecedor.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Representante");
        tabFornecedor.getTableHeader().getColumnModel().getColumn(2).setHeaderValue("Empresa Fantasia");

        tabFornecedor.setPreferredScrollableViewportSize(new Dimension(2300, 0));



    }

    public void primeiraLeitura() {
        btnSalvarCliente.setEnabled(false);
//        btnAlterar.setEnabled(false);
//        btnExluirCliente.setEnabled(false);
        btnCancelar.setEnabled(false);
        btnNovoCliente.setEnabled(true);

        txtNomeP.setText("");
        txtCodigo.setText("");
        txtPreco.setText("");
        txtNomeF.setText("");
        txtCodigoF.setText("");
        txtRepresentante.setText("");
        txtEstoqueMin.setText("");
        txtTamanho.setText("");
        txtMarca.setText("");

        txtPreco.setEnabled(false);
        txtPesquisaF.setEnabled(false);
        filtro2.setEnabled(false);
        txtNomeP.setEnabled(false);
        txtEstoqueMin.setEnabled(false);
        txtMarca.setEnabled(false);
        txtTamanho.setEnabled(false);


        formWindowOpenedF(
                null);

        setVisible(
                true);



    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnNovoCliente;
    private javax.swing.JButton btnSalvarCliente;
    private javax.swing.JComboBox filtro2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable tabFornecedor;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtCodigoF;
    private javax.swing.JTextField txtEstoqueMin;
    private javax.swing.JTextField txtMarca;
    private javax.swing.JTextField txtNomeF;
    private javax.swing.JTextField txtNomeP;
    private javax.swing.JTextField txtPesquisaF;
    private javax.swing.JFormattedTextField txtPreco;
    private javax.swing.JTextField txtRepresentante;
    private javax.swing.JTextField txtTamanho;
    // End of variables declaration//GEN-END:variables
}
